var Books = {};

Books.index = {
	//初始化
	init : function(_path) {
	    Books.index.path = _path;
		this.lis = $("#list-type-menu").find(">li");
		this.nowShow = $("#carousel");
		this.addListener();
		this.addListenerTop();
	},
	//添加必要的监听器
	addListener : function() {
		// 进入详细内容时保持显示
		var i;
		for (i = 0; i < this.lis.length; i++) {
			var strBox = Books.index.lis.eq(i).attr("data-target");
			$(strBox).mouseenter(function() {
				Books.index.nowShow.removeClass("show").addClass("hide");
				$(this).removeClass("hide").addClass("show");
			}).mouseleave(function() {
				$(this).removeClass("show").addClass("hide");
				Books.index.nowShow = $("#carousel");
				Books.index.nowShow.removeClass("hide").addClass("show");
			});
		}

		// 进入菜单项时显示对应的详细内容
		for (i = 0; i < this.lis.length; i++) {
			this.lis.eq(i).mouseenter(function() {
				var strBox = $(this).attr("data-target");
				Books.index.nowShow.removeClass("show").addClass("hide");
				Books.index.nowShow = $(strBox);
				Books.index.nowShow.removeClass("hide").addClass("show");
			});
			this.lis.eq(i).mouseleave(function() {
				Books.index.nowShow.removeClass("show").addClass("hide");
				Books.index.nowShow = $("#carousel");
				Books.index.nowShow.removeClass("hide").addClass("show");
			});
		}
	},
	addListenerTop:function(){
        // 模态框打开时更改验证码图片
        $("#login-modal").on("show.bs.modal", function() {
            Books.index.loginModalOpen();
        });

        // 点击图片更改验证码
        $("#img-verify").click(function() {
            Books.index.switchVerifyImage();
        });
        // 用户名失去焦点验证用户名
        $("#input-username").blur(function() {
            Books.index.judgeUserName();
        }).keypress(function(e) {
            if (e.keyCode === 13) {
                e.preventDefault();
                $("#input-password")[0].focus();
            }
        });
        // 密码框失去焦点验证密码
        $("#input-password").blur(function() {
            Books.index.judgePassword();
        }).keypress(function(e) {
            if (e.keyCode === 13) {
                e.preventDefault();
                $("#input-verify")[0].focus();
            }
        });
        // 验证码输入框失去焦点验证验证码格式
        $("#input-verify").blur(function() {
            Books.index.judgeVerify();
        }).keypress(function(e) {
            if (e.keyCode === 13) {
                e.preventDefault();
                $("#login").click();
            }
        });
        // 登陆按钮点击事件
        $("#login").click(function() {
            Books.index.login();
        });
        //退出登录按钮点击事件
        $("#top-remove-user").click(function(){
            Books.index.logout();
        });
        // QQ登陆
        $("#QQ").click(function() {
            Books.index.loginByQQ();
        });
        // 微信登陆
        $("#WeiXin").click(function() {
            Books.index.loginByWeiXin();
        });
        // 新浪微博登陆
        $("#WeiBo").click(function() {
            Books.index.loginByWeiBo();
        });
	},
	// 登陆模态框打开前拦截
	loginModalOpen : function() {
		// 更换验证码图片
		Books.index.switchVerifyImage();
		Books.index.setUsernameNormal();
		Books.index.setPasswordNormal();
		Books.index.setVerifyNormal();
        $("#username-help").html("");
        $("#password-help").html("");
        $("#verify-help").html("");
        $("#input-username").val('');
        $("#input-password").val('');
        $("#input-verify").val('');
	},
	// 设置窗口为错误模式
	setInputError : function(target) {
		$(target).removeClass("has-success").removeClass("has-warning")
				.addClass("has-error");
		$(target).children("span.glyphicon").removeClass("glyphicon-ok")
				.removeClass("glyphicon-warning-sign").addClass(
						"glyphicon-remove");
	},
	// 设置窗口为成功模式
	setInputSuccess : function(target) {
		$(target).removeClass("has-error").removeClass("has-warning").addClass(
				"has-success");
		$(target).children("span.glyphicon").removeClass("glyphicon-remove")
				.removeClass("glyphicon-warning-sign").addClass("glyphicon-ok");
	},
	// 设置窗口为普通模式
	setInputNormal : function(target) {
		$(target).removeClass("has-error").removeClass("has-warning")
				.removeClass("has-success");
		$(target).children("span.glyphicon").removeClass("glyphicon-remove")
				.removeClass("glyphicon-warning-sign").removeClass(
						"glyphicon-ok");
	},
	// 设置验证码显示值
	setVerify : function(date) {
		$("#input-verify").val(date);
	},
	// 切换验证码图片
	switchVerifyImage : function() {
		$("#login-modal").find(".modal-body form #img-verify").css(
				"background-image",
				"url('"+Books.index.path+"/loginImage.do?a=" + new Date().getTime() + "')");
		// 清空验证码输入框
		this.setVerify("");
		this.setVerifyNormal();
	},
	// 设置用户名登陆框错误提示
	setUsernameErr : function(str) {
		if (str === null || str.length === 0) {
			$("#username-help").html("");
			Books.index.setInputSuccess($("#username-group"));
		} else {
			$("#username-help").html(str);
			Books.index.setInputError($("#username-group"));
		}
	},
	// 设置密码框错误提示
	setPasswordErr : function(str) {
		if (str === null || str.length === 0) {
			$("#password-help").html("");
			Books.index.setInputSuccess($("#password-group"));
		} else {
			$("#password-help").html(str);
			Books.index.setInputError($("#password-group"));
		}
	},
	// 设置验证码错误提示
	setVerifyErr : function(str) {
		if (str === null || str.length === 0) {
			$("#verify-help").html("");
			Books.index.setInputSuccess($("#verify-group"));
		} else {
			$("#verify-help").html(str);
			Books.index.setInputError($("#verify-group"));
		}
	},
	// 设置验证码错误提示
	setUsernameNormal : function() {
		Books.index.setInputNormal($("#username-group"));
	},
	// 设置验证码错误提示
	setPasswordNormal : function() {
		Books.index.setInputNormal($("#password-group"));
	},
	// 设置验证码错误提示
	setVerifyNormal : function() {
		Books.index.setInputNormal($("#verify-group"));
	},
	// 验证用户名的正确性，正确返回true，错误则显示错误，更改输入框为error模式，并返回false
	judgeUserName : function() {
		var target = $("#input-username").val();
		var index = Books.index;
		if (target === null || target.length === 0) {
			index.setUsernameErr("用户名不能为空...");
			return false;
		} else if (target.length < 6) {
			index.setUsernameErr("用户名不得少于6个字符...");
			return false;
		} else {
			// 格式正确
			index.setUsernameErr(null);
			return true;
		}
	},
	// 验证密码框格式，正确返回true，错误设置错误信息并返回false
	judgePassword : function() {
		var target = $("#input-password").val();
		var index = Books.index;
		if (target === null || target.length === 0) {
			index.setPasswordErr("密码不能为空..");
			return false;
		} else if (target.length < 8) {
			index.setPasswordErr("密码不得少于8个字符...");
			return false;
		} else if (target.length > 20) {
			index.setPasswordErr("密码不得多于20个字符...");
			return false;
		} else if (/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]$/.test(target)) {
			index.setPasswordErr("密码必须由字母、数字加英文符号构成（不包含空格）...");
			return false;
		} else {
			index.setPasswordErr(null);
			return true;
		}
	},
	// 验证验证码框输入格式，正确返回true，错误则设置错误信息并返回false
	judgeVerify : function() {
		var target = $("#input-verify").val();
		var index = Books.index;
		if (target === null || target.length === 0) {
			index.setVerifyErr("验证码不能为空...");
			return false;
		} else if (target.length < 4) {
			index.setVerifyErr("验证码长度至少4位...");
			return false;
		} else if (!/^[0-9a-zA-Z]*$/.test(target)) {
			index.setVerifyErr("验证码只能为数字和字母...");
			return false;
		} else {
			index.setVerifyErr(null);
			return true;
		}
	},
	// 登陆验证
	login : function() {
		if (Books.index.judgeUserName() && Books.index.judgePassword()
				&& Books.index.judgeVerify()) {
			var user = $("#input-username").val();
			var pass = $("#input-password").val();
			var veri = $("#input-verify").val();
			var sa = $("#save").get(0).checked;
			$.post(Books.index.path+"/login.do", {
				"username" : user,
				"password" : pass,
				"verify" : veri,
				"isSave" : sa
			}, function(obj, status) {
				console.log(status + "\n" + obj.toString());
				if (status === "success") {
					if (obj.code === 200) {
						console.log("登陆成功");
						Books.index.loginSuccess(obj);
						// 隐藏模态框
						$('#login-modal').modal('hide');
					} else if (obj.code === 404) {
						console.log("用户不存在");
						// 更改验证码
						Books.index.switchVerifyImage();
						// 设置错误信息
						Books.index.setUsernameErr("用户不存在，请重新输入...");
					} else if (obj.code === 405) {
						console.log("密码错误");
						// 更改验证码
						Books.index.switchVerifyImage();
						// 设置错误信息
						Books.index.setPasswordErr("密码错误，请重新输入...");
					} else if (obj.code === 403) {
						console.log("验证码错误");
						// 更改验证码
						Books.index.switchVerifyImage();
						// 设置错误信息
						Books.index.setVerifyErr("验证码错误，请重新输入...");
					} else {
						console.log("错误的返回结果");
					}
				} else {
					alert("请求失败");
				}
			});
		}
	},
	//通过QQ登陆
	loginByQQ : function() {
		alert("Login by QQ");
	},
	//通过微信登陆
	loginByWeiXin : function() {
		alert("Login by QQ");
	},
	//通过微博登陆
	loginByWeiBo : function() {
		alert("Login by QQ");
	},
	// 登陆成功后的业务逻辑
	loginSuccess : function(user) {
		console.log("登陆成功...");
		$("#btn-login").removeClass("show").addClass("hide");
		$("#btn-register").removeClass("show").addClass("hide");
        $("#top-user").removeClass("hide").addClass("show").find("a").html(user.data.user.nickname);
        $("#top-remove-user").removeClass("hide").addClass("show");
	},
	//退出登录
	logout:function(){
		console.log("lougou");
		$.post(Books.index.path+"/logout.do", {}, function(data, status){
			console.log(status+"\n"+data);
			if(status === "success"){
				//退出成功
				console.log("退出");
				if(data.code === 200){
                    $("#btn-login").removeClass("hide").addClass("show");
                    $("#btn-register").removeClass("hide").addClass("show");
                    $("#top-user").addClass("hide").removeClass("show").find("a").html("");
                    $("#top-remove-user").addClass("hide").removeClass("show");
				}else{
					console.log("logout success");
				}
			}
		});
	}
};

Books.index.register = {
	init : function() {
		// 六个输入框实例
		this.inputNickname = $("#_input-nickname");
		this.inputPhone = $("#_input-phone");
		this.inputPassword1 = $("#_input-password");
		this.inputPassword2 = $("#_input-password2");
		this.inputVerify = $("#_input-verify");
		this.inputMsgVerify = $("#_input-phone-number");
		// 六个输入框组的实例
		this.groupNickname = $("#_nickname-group");
		this.groupPhone = $("#_phone-group");
		this.groupPassword1 = $("#_password-group");
		this.groupPassword2 = $("#_password-group2");
		this.groupVerify = $("#_verify-group");
		this.groupMsgVerify = $("#_verify-phone-group");
		// 六个错误显示信息
		this.helpNickname = $("#_nickname-help");
		this.helpPhone = $("#_phone-help");
		this.helpPassword1 = $("#_password-help");
		this.helpPassword2 = $("#_password-help2");
		this.helpVerify = $("#_verify-help");
		this.helpMsgVerify = $("#_phone-number-help");

		this.spanVerify = $("#register-modal").find(".modal-body form #_show-verify");
		this.spanMsgVerify = $("#_get-phone-verify");

		this.btnRegister = $("#register");

		this.timer = null;
		this.t = 60;
		this.msgGet = false;

		this.addListener();
	},
	addListener : function() {
		// 模态框打开时更改验证码图片
		$("#register-modal").on("show.bs.modal", function() {
			Books.index.register.registerOpen();
		}).on('hidden.bs.modal', function () {
            Books.index.register.registerClose();
        });
		this.btnRegister.click(function(){
			Books.index.register.register();
		});
		this.spanVerify.click(function(){
            Books.index.register.switchVerify();
		});
		this.spanMsgVerify.click(function(){
            Books.index.register.getMsgVerify();
		});
		this.inputNickname.blur(function(){
			Books.index.register.judgeNickname();
		}).keypress(function(e) {
            if (e.keyCode === 13) {
                e.preventDefault();
                Books.index.register.inputPhone.get(0).focus();
            }
        });
        this.inputPhone.blur(function(){
            Books.index.register.judgePhone();
        }).keypress(function(e) {
            if (e.keyCode === 13) {
                e.preventDefault();
                Books.index.register.inputPassword1.get(0).focus();
            }
        });
        this.inputPassword1.blur(function(){
            Books.index.register.judgePassword1();
        }).keypress(function(e) {
            if (e.keyCode === 13) {
                e.preventDefault();
                Books.index.register.inputPassword2.get(0).focus();
            }
        });
        this.inputPassword2.blur(function(){
            Books.index.register.judgePassword2();
        }).keypress(function(e) {
            if (e.keyCode === 13) {
                e.preventDefault();
                Books.index.register.inputVerify.get(0).focus();
            }
        });
        this.inputVerify.blur(function(){
            Books.index.register.judgeVerify();
        }).keypress(function(e) {
            if (e.keyCode === 13) {
                e.preventDefault();
                Books.index.register.inputMsgVerify.get(0).focus();
            }
        });
        this.inputMsgVerify.blur(function(){
            Books.index.register.judgeMsgVerify();
        }).keypress(function(e) {
            if (e.keyCode === 13) {
                e.preventDefault();
                Books.index.register.btnRegister.click();
            }
        });
	},
	registerOpen : function() {
		this.inputNickname.val("");
		this.inputPhone.val("");
		this.inputPassword1.val("");
		this.inputPassword2.val("");
		this.inputVerify.val("");
		this.inputMsgVerify.val("");
		this.setGroupNormal(this.groupNickname);
		this.setGroupNormal(this.groupPhone);
		this.setGroupNormal(this.groupPassword1);
		this.setGroupNormal(this.groupPassword2);
		this.setGroupNormal(this.groupVerify);
		this.setGroupNormal(this.groupMsgVerify);
		this.helpNickname.html("");
		this.helpPhone.html("");
		this.helpPassword1.html("");
		this.helpPassword2.html("");
		this.helpVerify.html("");
		this.helpMsgVerify.html("");

		this.spanMsgVerify.html("获取验证码");
		this.switchVerify();

		this.timer = null;
		this.t = 60;
        this.msgGet = false;
        this.spanMsgVerify.removeClass("disabled");
	},
	registerClose:function(){
		if(this.timer !== null){
			window.clearInterval(this.timer);
			this.timer = null;
			this.t = 60;
			this.msgGet = false;
			this.spanMsgVerify.removeClass("disabled");
		}
	},
	register : function() {
        //首先将注册按钮设置为禁用
		var register = Books.index.register;
        register.disabledBtn(register.btnRegister);
        if (!register.judgeNickname() || !register.judgePhone() || !register.judgePassword1() || !register.judgePassword2() || !register.judgeVerify() || !register.judgeMsgVerify()) {
            register.unDisabledBtn(register.btnRegister);
            console.log("表单错误");
            return false;
        }
        var _nick = register.inputNickname.val();
        var _phon = register.inputPhone.val();
        var _pass1 = register.inputPassword1.val();
        var _veri = register.inputVerify.val();
        var _sms = register.inputMsgVerify.val();
        $.post(Books.index.path+"/register.do",{
        	"nick" : _nick,
			"phon" : _phon,
			"pass" : _pass1,
			"veri" : _veri,
			"sms" : _sms
		},function(obj, status){
        	console.log(obj);
			if(status === "success"){
				//访问成功
				var re = Books.index.register;
				console.log(obj.code);
				switch(obj.code){
					case 200:
                        //成功
						swal({
							title:"提示",
							text:"注册成功,是否返回登陆...",
							type:"success",
							showCancelButton:true,
							confirmButtonText:"是",
							cancelButtonText:"返回"
						}).then(function(isConfirm){
							console.log(isConfirm);
							if(isConfirm.value === true){
								//点击了是，关闭注册框，打开登陆框
								$("#register-modal").modal("hide");
                                $("#login-modal").modal("show");
							}
						});
						break;
					case 406:
                    case 407:
						//参数错误
						console.log("参数错误...");
						break;
					case 403:
						//验证码错误
						re.inputVerify.val("");
						re.helpVerify.html("验证码错误...");
						re.setGroupError(re.groupVerify);
						re.switchVerify();
						re.inputVerify.get(0).focus();
						break;
                    //短信验证码错误
                    case 408:
                        //还没有获取短信验证码
                        re.inputMsgVerify.val("");
                        re.helpMsgVerify.html("验证码错误...");
                        re.setGroupError(re.groupMsgVerify);
                        re.inputMsgVerify.get(0).focus();
						break;
					case 409:
						//用户已经存在
                        re.helpPhone.html("号码已经注册或绑定...");
                        re.setGroupError(re.groupPhone);
                        re.inputPhone.get(0).focus();
						break;
				}
			}else{
				//访问失败
				console.log("链接servlet失败...");
			}
            register.unDisabledBtn(register.btnRegister);
		});
    },
	switchVerify : function() {
		this.spanVerify.css(
			"background-image",
			"url('"+Books.index.path+"/registerImage.do?a=" + new Date().getTime() + "')");
		this.inputVerify.val("");
		this.setGroupNormal(this.groupVerify);
	},
	judgeNickname:function(){
		var target = this.inputNickname.val();
		if(target === null || target.length === 0){
			this.helpNickname.html("昵称不能为空...");
			this.setGroupError(this.groupNickname);
			return false;
		}else if(target.length < 6){
            this.helpNickname.html("昵称不能少于6个字符...");
            this.setGroupError(this.groupNickname);
            return false;
		}else if(target.indexOf(" ") !== -1){
            this.helpNickname.html("昵称不能包含空格...");
            this.setGroupError(this.groupNickname);
            return false;
		}else{
            this.helpNickname.html("");
            this.setGroupSuccess(this.groupNickname);
            return true;
		}
	},
	judgePhone:function(){
		var target = this.inputPhone.val();
		if(target === null || target.length === 0){
            this.helpPhone.html("手机号码不能为空...");
            this.setGroupError(this.groupPhone);
            return false;
		}else if(target.length !== 11){
            this.helpPhone.html("手机号码应为11位数字...");
            this.setGroupError(this.groupPhone);
            return false;
		}else if(!/^1[34578][0-9]{9}$/.test(target)){
            this.helpPhone.html("不是一个正确的手机号码...");
            this.setGroupError(this.groupPhone);
            return false;
		}else{
            this.helpPhone.html("");
            this.setGroupSuccess(this.groupPhone);
            return true;
		}
	},
	judgePassword1:function(){
        var target = this.inputPassword1.val();
        if (target === null || target.length === 0) {
            this.helpPassword1.html("密码不能为空..");
            this.setGroupError(this.groupPassword1);
            return false;
        } else if (target.length < 8) {
            this.helpPassword1.html("密码不得少于8个字符...");
            this.setGroupError(this.groupPassword1);
            return false;
        } else if (target.length > 20) {
            this.helpPassword1.html("密码不得多于20个字符...");
            this.setGroupError(this.groupPassword1);
            return false;
        } else if (/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]$/.test(target)) {
            this.helpPassword1.html("密码必须由字母、数字加英文符号构成（不包含空格）...");
            this.setGroupError(this.groupPassword1);
            return false;
        } else {
            this.helpPassword1.html("");
            this.setGroupSuccess(this.groupPassword1);
            return true;
        }
	},
	judgePassword2:function(){
        var target = this.inputPassword1.val();
        var target2 = this.inputPassword2.val();
        if (target === null || target.length === 0) {
            this.helpPassword2.html("密码不能为空...");
            this.setGroupError(this.groupPassword2);
            return false;
        } else if (target.length < 8) {
            this.helpPassword2.html("密码不得少于8个字符...");
            this.setGroupError(this.groupPassword2);
            return false;
        } else if (target.length > 20) {
            this.helpPassword2.html("密码不得多于20个字符...");
            this.setGroupError(this.groupPassword2);
            return false;
        } else if (/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]$/.test(target)) {
            this.helpPassword2.html("密码必须由字母、数字加英文符号构成（不包含空格）...");
            this.setGroupError(this.groupPassword2);
            return false;
        } else if(target2 === null || target !== target2){
            this.helpPassword2.html("两次密码不一致...");
            this.setGroupError(this.groupPassword2);
            return false;
		}else {
            this.helpPassword2.html("");
            this.setGroupSuccess(this.groupPassword2);
            return true;
        }
	},
	judgeVerify:function(){
        var target = this.inputVerify.val();
        if (target === null || target.length === 0) {
			this.helpVerify.html("验证码不能为空...");
			this.setGroupError(this.groupVerify);
            return false;
        } else if (target.length < 4) {
            this.helpVerify.html("验证码长度至少4位...");
            this.setGroupError(this.groupVerify);
            return false;
        } else if (!/^[0-9a-zA-Z]*$/.test(target)) {
            this.helpVerify.html("验证码只能为数字和字母...");
            this.setGroupError(this.groupVerify);
            return false;
        } else {
            this.helpVerify.html("");
            this.setGroupSuccess(this.groupVerify);
            return true;
        }
	},
	judgeMsgVerify:function(){
        var target = this.inputMsgVerify.val();
        if (target === null || target.length === 0) {
            this.helpMsgVerify.html("短信验证码不能为空...");
            this.setGroupError(this.groupMsgVerify);
            return false;
        } else if (target.length < 4) {
            this.helpMsgVerify.html("短信验证码长度至少4位...");
            this.setGroupError(this.groupMsgVerify);
            return false;
        } else if (!/^[0-9]*$/.test(target)) {
            this.helpMsgVerify.html("短信验证码只能为纯数字...");
            this.setGroupError(this.groupMsgVerify);
            return false;
        } else {
            this.helpMsgVerify.html("");
            this.setGroupSuccess(this.groupMsgVerify);
            return true;
        }
	},
	getMsgVerify:function(){
		if(this.msgGet) return;
		if(!this.judgePhone()){
			this.inputPhone.get(0).focus();
			return;
		}
		if(!this.judgeVerify()){
			this.inputVerify.get(0).focus();
			return;
		}
		var _verify = this.inputVerify.val();
		var _phone = this.inputPhone.val();
		$.post(Books.index.path+"/sendRegisterSms.do", {
			"verify" : _verify,
			"phone" : _phone
		}, function(obj, status){
			//消息返回函数
			if(status === "success"){
			    console.log(obj);
                if(obj.code === 200){
                	//发送短信成功
					console.log("短信发送成功...");
					Books.index.register.sendSmsSuccess();
				}else if(obj.code === 403){
					//验证码错误
					console.log("验证码错误...");
					Books.index.register.verifyErr();
				}else if(obj.code === 500){
                	//发送短信失败
					console.log(obj.data);
					var code = obj.data.split("#")[0];
					console.log("code : "+code);
					switch(code){
						case "00174":
							console.log("一分钟内下发短信超过次数限制");
							Books.index.register.helpPhone.html("一分钟内下发短信超过次数限制,请更换号码或者稍后再试...");
                            Books.index.register.setGroupError(Books.index.register.groupPhone);
							break;
                        case "00141":
                        	console.log("一小时内发送给单个手机次数超过限制");
                            Books.index.register.helpPhone.html("一小时内发送给单个手机次数超过限制,请更换号码或者稍后再试...");
                            Books.index.register.setGroupError(Books.index.register.groupPhone);
                            break;
                        case "00142":
                        	console.log("一天内发送给单个手机次数超过限制");
                            Books.index.register.helpPhone.html("一天内发送给单个手机次数超过限制,请更换号码或者稍后再试...");
                            Books.index.register.setGroupError(Books.index.register.groupPhone);
                            break;
						default:
							break;
					}
				}
			}
		});

	},
	verifyErr:function(){
		this.switchVerify();
        this.setGroupError(this.groupVerify);
		this.inputVerify.val("");
		this.helpVerify.html("验证码错误...");
		this.inputVerify.get(0).focus();
	},
	sendSmsSuccess:function(){
        this.msgGet = true;
        this.spanMsgVerify.addClass("disabled");
        this.t = 60;
        this.spanMsgVerify.html(this.t--);
        this.timer = setInterval(function(){
            var register = Books.index.register;
            register.spanMsgVerify.html(register.t--);
            if(register.t <= 0){
                window.clearInterval(register.timer);
                register.t = 60;
                register.msgGet = false;
                register.spanMsgVerify.html("获取验证码");
                register.spanMsgVerify.removeClass("disabled");
            }
        }, 1000);
	},
	setGroupError : function(target) {
        $(target).removeClass("has-success").removeClass("has-warning")
            .addClass("has-error");
        $(target).find("span.glyphicon").removeClass("glyphicon-ok")
            .removeClass("glyphicon-warning-sign").addClass(
            "glyphicon-remove");
    },
    // 设置窗口为成功模式
    setGroupSuccess : function(target) {
        $(target).removeClass("has-error").removeClass("has-warning").addClass(
            "has-success");
        $(target).find("span.glyphicon").removeClass("glyphicon-remove")
            .removeClass("glyphicon-warning-sign").addClass("glyphicon-ok");
    },// 设置窗口为普通模式
    setGroupNormal : function(target) {
        $(target).removeClass("has-error").removeClass("has-warning")
            .removeClass("has-success");
        $(target).find("span.glyphicon").removeClass("glyphicon-remove")
            .removeClass("glyphicon-warning-sign").removeClass(
            "glyphicon-ok");
    },
	//禁用按钮
	disabledBtn:function(target){
		if(target !== null){
			target.addClass("disabled");
		}
	},
	//将禁用按钮恢复
	unDisabledBtn:function(target){
		if(target !== null){
			target.removeClass("disabled");
		}
	}
};

Books.index.inited = {
	init:function(){
		this.doRecodeImage();
		this.doClickBook();
		this.doClickSmallBook();
	},
    doRecodeImage: function(){
	    $("#phone-book").mouseenter(function(){
	        $("#phone-book-image").css("display", "block");
        }).mouseleave(function(){
            $("#phone-book-image").css("display", "none");
        });
        $("#wei-book").mouseenter(function(){
            $("#wei-book-image").css("display", "block");
        }).mouseleave(function(){
            $("#wei-book-image").css("display", "none");
        });
    },
    doClickBook:function(){
        $(".book").click(function(){
            window.open(Books.index.path+"/page/book/id/"+$(this).attr("bookid")+".do");
        });
    },
    doClickSmallBook:function(){
        $(".smallBook").click(function(){
            window.open(Books.index.path+"/page/book/id/"+$(this).attr("bookid")+".do");
        });
    }
};